package cn.oesoft.blog.mapper;

import cn.oesoft.blog.model.domain.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;

@Mapper
public interface UserMapper {

    // 新增用户，同时使用@Options注解获取自动生成的主键id
    @Insert("INSERT INTO t_user (username,password,email,created,valid) " +
            " VALUES (#{username},#{password}, #{email}, #{created}, #{valid}) ")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    public Integer addUser(User user);

    //给新用户分配权限，默认是普通用户，权限id=2
    @Insert("INSERT INTO t_user_authority (user_id,authority_id) " +
            " VALUES (#{id},2) ")
    public Integer giveAuthorityToNewUser(User user) ;

}
